package com.yulan.fastkillcourse.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yulan.fastkillcourse.model.Course;
import com.yulan.fastkillcourse.model.CourseDiscuss;
import com.yulan.fastkillcourse.model.CourseOrder;
import com.yulan.fastkillcourse.result.CodeMsg;
import com.yulan.fastkillcourse.result.Result;
import com.yulan.fastkillcourse.service.*;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 学生操作的controller
 */
@RestController
@RequestMapping("student")
public class StudentController {
    @Autowired
    CourseService courseService;

    @Autowired
    CourseMarginService courseMarginService;

    @Autowired
    CourseTrackService courseTrackService;

    @Autowired
    CourseDiscussService courseDiscussService;

    @Autowired
    CourseOrderService courseOrderService;

    @Autowired
    RedisTemplate<String,String> redisTemplate;


    @Autowired
    ModelMapper modelMapper;


    @PostMapping("/addDiscusAndScore")
    public Result<Boolean> putCourseDiscuss( @RequestBody CourseDiscuss courseDiscuss){
        if(courseDiscuss == null) return Result.error(CodeMsg.PARAM_EXCEPTION);
        Boolean isSuccess = courseDiscussService.save(courseDiscuss);

        return new Result<>(isSuccess);
    }

    @PostMapping("/delDiscusAndScore")
    public Result<Boolean> delCourseDiscuss(@RequestParam int did){
        Boolean isSuccess = courseDiscussService.removeById(did);

        return new Result<>(isSuccess);
    }

    /**
     * 学生获取自己选的课
     */
    @GetMapping("/getPickCourses")
    public Result<List<CourseOrder>> getPickCourses(@RequestParam int uid){

        QueryWrapper<CourseOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("uid",uid);
        List<CourseOrder> courseOrderList = courseOrderService.list(queryWrapper);

        if(courseOrderList==null) return Result.error(CodeMsg.NULL_ANS);

        return new Result<>(courseOrderList);
    }


}
